<template>
    <div>
        <div class="header" style="background-color: white">
            <el-page-header  content="工资录入">
            </el-page-header>
        </div>
        <el-divider></el-divider>
        <el-row>
            <el-col :span="12"><h1 style="margin-left: 86px">员工工资录入</h1></el-col>
            <el-col :span="12"></el-col>
        </el-row>
        <el-form style="margin-left: 70px;margin-top: 20px">
            <el-container style="margin-top: 50px">
                <el-form-item >
                    <el-select  @change="empSalary" v-model="emp.hrEmpId" placeholder="选择员工" style="margin-left: 20px;width: 300px"  >
                        <el-option
                                v-for="item in emps"
                                :key="item.id"
                                :label="item.emp_name"
                                :value="item.id"

                        >
                        </el-option>
                    </el-select>
                    <el-date-picker
                            style="width: 300px;margin-left: 50px"
                            v-model="emp.cwEmpincomeDate"
                            type="date"
                            placeholder="选择日期" value-format="yyyy-MM-dd">
                    </el-date-picker>
                </el-form-item>
            </el-container>
            <el-container style="margin-top: 50px">
            <el-form-item label="基本工资：" style="margin-left: 20px">
                <el-input style="width: 300px;" type="number" v-model="emp.cwBasicSalary" readonly=""></el-input>
            </el-form-item>
                <el-form-item label="级别工资:" style="margin-left: 50px">
                    <el-input v-model="emp.cwLevelSalary" style="width: 300px" readonly=""></el-input>
                </el-form-item>
            </el-container>

            <el-container style="margin-top: 50px;margin-left: 20px">
                <el-form-item>
                    <el-button type="primary" @click="checkCommit">确认提交</el-button>
                </el-form-item>
            </el-container>
        </el-form>
    </div>
</template>

<script>
    import CwEmpincomeService from '../../../model/ww/cw_inout/CwEmpincomeService'

    const cwEmpincomeService = CwEmpincomeService.getInstance();

    export default {
        name: "SalaryInsrt",
        data(){
            return {
                emps:[],//员工信息
                emp:{
                    cwBasicSalary:'',
                    cwLevelSalary:''

                }//员工对象
            }
        },
        methods:{
            List(){  //查询所有员工姓名
                cwEmpincomeService.empList().then((response)=>{
                    this.emps=response.data.data
                })
            },
            empSalary(val){
                this.emps.forEach(item=>{
                    if(item.id==val){
                       this.emp.cwBasicSalary=item.cw_lmoney
                        this.emp.cwLevelSalary=item.cw_basic
                    }
                })
            },
            checkCommit(){ //添加员工工资
                cwEmpincomeService.save(this.emp).then(()=>{
                    //重新加载查询方法
                    this.List();
                    //格式化
                    this.emp.cwBasicSalary=''
                    this.emp.cwLevelSalary=''
                    this.emp.hrEmpId=''
                    this.emp.cwEmpincomeDate=''
                    this.$message('录入成功')
                })
            }

        }
        ,
        created(){
            this.List()
        }
    }
</script>

<style scoped>

</style>